var OID ="";
var LID ="";
var MP ="";

var useEfSch = false;
var useEf2Sch = false;
var searchByYsOnly = 0;
var html = '';
var c = '';


/*Drop Down Search Begin*/
var useEfQuickSearch = false;

function QuickSearchRedirect(result)
{
	useEfQuickSearch = result;
}

function GetDropDownData(sel,text,varName,parameters,defaultVal,productTypeNumId,postfixId)
{
	if(sel == null)
	{
		return;
	}
	ClearDropDown(sel,"Loading...");

	var url = "";
	if(useEfQuickSearch == true)
	{
		url = "http://search10.eforcity.com/EFQuickSearch/QuickSearchEngine.aspx?" + parameters;
	}
	else
	{
		url = "http://search.eforcity.com/EFQuickSearchTest/QuickSearchEngine.aspx?" + parameters;
	}

	var divCat = document.getElementById("divCategory");
	if(divCat != null)
	{
		var script = document.createElement("script");
		script.src = url;
		script.type = "text/javascript";
		divCat.appendChild(script);

		if (!/*@cc_on!@*/0)
		{
			script.onload = function()
			{
				BindDropDown(sel,text,varName,defaultVal,productTypeNumId,postfixId);
			}
		}
		else
		{
			script.onreadystatechange = function()
			{
				if (script.readyState == 'loaded' || script.readyState == 'complete')
				{
					BindDropDown(sel,text,varName,defaultVal,productTypeNumId,postfixId);
				}
			}
		}
	}
}

function BindDropDown(sel,text,varName,defaultVal,productTypeNumId,postfixId)
{
	var dropDownData = null;
	var hasData = false;
	try
	{
		dropDownData = eval("data" + varName);
		hasData = true;
	}
	catch(e)
	{
		hasData = false;
	}

	ClearDropDown(sel,text);
	if(hasData == true)
	{
		if(sel != null && dropDownData != null)
		{
			for(i = 0; i < dropDownData.length; i++)
			{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					sel.options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
			}
		}
		defaultVal = defaultVal == null ? 0 : defaultVal;
		SetDisabledByLength(sel);
		SetDefaultValue(sel,defaultVal);
		SetHiddenValue(productTypeNumId,postfixId);
	}
}

/*Page Load Inital Begin*/
function IndexPageLoad()
{
	InitalDropDown();
	ClearHiddenValue();
	var catSel = document.getElementById("CategoryMenuSel");
	if(catSel != null)
	{
		catSel.selectedIndex = 0;
	}
}
/*Page Load Inital End*/

/*For Index Page*/
function ChangeCategoryMenu(categoryNumId)
{
	ChangeDropDown(categoryNumId);

	var bdSel = document.getElementById("BrandSel");
	var ptSel = document.getElementById("ProductTypeSel");
	if(bdSel != null && ptSel != null)
	{
		if(categoryNumId > 0)
		{
			GetDropDownData(bdSel,"Select a brand","Brand","ro=Brand&cni=" + categoryNumId);
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + categoryNumId);
		}
		else
		{
			ClearDropDown(bdSel,"Select a brand");
			SetDisabled(bdSel,true);
			ClearDropDown(ptSel,"Select a product type");
			SetDisabled(ptSel,true);
		}
	}
}
function ChangeDropDown(categoryNumId)
{
	if(categoryNumId > 0)
	{
		ChangeMainBanner(categoryNumId);
	}

	var categoryDiv = document.getElementById('CategoryDiv');
	var subProductTypeDiv = document.getElementById('SubProductTypeDiv');
	var lengthDiv = document.getElementById('LengthDiv');
	if(categoryDiv != null && subProductTypeDiv != null)
	{
		if(categoryNumId == 1 || categoryNumId == 8)
		{
			categoryDiv.style.display = "none";
			subProductTypeDiv.style.display = "block";
			if(categoryNumId == 1)
			{
				lengthDiv.style.display = "block";
			}
			else
			{
				lengthDiv.style.display = "none";
			}
		}
		else
		{
			categoryDiv.style.display = "block";
			subProductTypeDiv.style.display = "none";
			lengthDiv.style.display = "none";
		}
	}
	ClearDropDownValue();
	ClearHiddenValue();

	var divCat = document.getElementById("divCategory");
	if(divCat != null)
	{
		divCat.innerHTML = "";
	}
}
function ChangeMainBanner(categoryNumId)
{
	var divBannerMenu = getElementsByNameFixed("div","divBannerMenu");
	if(divBannerMenu != null)
	{
		for(i = 0; i < divBannerMenu.length; i++)
		{
			divBannerMenu[i].style.display = "none";
		}
		LoadBannerImage(categoryNumId);
	}
}
function LoadBannerImage(categoryNumId)
{
	var divBanner = document.getElementById("divBannerMenu" + categoryNumId);
	if(divBanner != null)
	{
		switch(parseInt(categoryNumId))
		{
			case 1: //AV
				divBanner.innerHTML = '<a href="http://www.eforcity.com/hdmi.html?int=efindxbanfsh08-av"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddav_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 2: //CELL
				divBanner.innerHTML = '<a href="http://www.eforcity.com/cell-phone-accessories-shop-by-all-brands.html?int=efindxbanfsh01-cp"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddcp_dec_01_2010.jpg" width="370" height="268" /></a>';				
				break;
			case 3: //DV
				divBanner.innerHTML = '<a href="http://www.eforcity.com/digital-videos-more.html?int=efindxbanfsh03-dv"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_dddv_dec_01_2010.jpg" width="370" height="268" /></a>';				
				break;
			case 4: //GAME
				divBanner.innerHTML = '<a href="http://www.eforcity.com/games-more.html?int=efindxbanfsh06-game"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddgame_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 5: //INK
				divBanner.innerHTML = '<a href="http://www.eforcity.com/printer-inks-more.html?int=efindxbanfsh05-ink"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddink_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 6: //MP3
				divBanner.innerHTML = '<a href="http://www.eforcity.com/universal-headphones.html?int=efindxbanfsh02-mp3"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddmp3_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 8: //PC
				divBanner.innerHTML = '<a href="http://www.eforcity.com/computers-more.html?int=efindxbanfsh07-pc"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddpc_dec_01_2010_v2.jpg" width="370" height="268" /></a>';				
				break;			
			default:
				break;
		}
		divBanner.style.display = "block";
	}
}
function ClearDropDownValue()
{
	var srSel = document.getElementById("SeriesSel");
	var mdSel = document.getElementById("ModelSel");
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	ClearDropDown(srSel,"Select a series");
	SetDisabled(srSel,true);
	ClearDropDown(mdSel,"Select a model");
	SetDisabled(mdSel,true);
	ClearDropDown(sptSel,"Select a sub product type");
	SetDisabled(sptSel,true);
	ClearDropDown(lenSel,"Select a length");
	SetDisabled(lenSel,true);
}
/*End For Index Page*/

function ChangeBrand(bni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);

	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && srSel!= null && mdSel != null && ptSel != null)
		{
			GetDropDownData(srSel,"Select a series","Series","ro=Series&cni=" + catSel.value + "&bni=" + bni + "&pni=" + ptSel.value);
			GetDropDownData(mdSel,"Select a model","Model","ro=Model&cni=" + catSel.value + "&bni=" + bni + "&pni=" + ptSel.value);
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + catSel.value + "&bni=" + bni,ptSel.value);
		}
	}
}

function ChangeSeries(sni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var bdSel = document.getElementById("BrandSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);

	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && bdSel != null && mdSel != null && ptSel != null)
		{
			GetDropDownData(mdSel,"Select a model","Model","ro=Model&cni=" + catSel.value + "&bni=" + bdSel.value + "&sni=" + sni + "&pni=" + ptSel.value,mdSel.value);
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + catSel.value + "&bni=" + bdSel.value + "&sni=" + sni,ptSel.value);
		}
	}
}

function ChangeModel(mni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var bdSel = document.getElementById("BrandSel" + postfixId);
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);

	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && bdSel != null && srSel!= null && ptSel != null)
		{
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + catSel.value + "&bni=" + bdSel.value + "&sni=" + srSel.value + "&mni=" + mni,ptSel.value);
		}
	}
}

function ChangeProductType(pni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var bdSel = document.getElementById("BrandSel" + postfixId);
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");

	if(categoryNumId == 0)
	{
		if(catSel != null)
		{
			//For Index Page
			if(catSel.value > 0 && bdSel != null && srSel!= null && mdSel != null && sptSel != null)
			{
				var bni = bdSel.value;
				var sni = srSel.value;
				var mni = mdSel.value;
				GetDropDownData(bdSel,"Select a brand","Brand","ro=Brand&cni=" + catSel.value + "&pni=" + pni,bni);
				GetDropDownData(srSel,"Select a series","Series","ro=Series&cni=" + catSel.value + "&bni=" + bni + "&pni=" + pni,sni);
				GetDropDownData(mdSel,"Select a model","Model","ro=Model&cni=" + catSel.value + "&bni=" + bni + "&sni=" + sni + "&pni=" + pni,mni);
				GetDropDownData(sptSel,"Select a sub product type","SubProductType","ro=SubProductType&cni=" + catSel.value + "&bni=" + bni + "&sni=" + sni + "&mni=" + mni + "&pni=" + pni);
			}
		}
	}

	ClearDropDown(lenSel,"Select a length");
	SetDisabled(lenSel,true);
}

function ChangeSubProductType(spni)
{
	var catSel = document.getElementById("CategoryMenuSel");
	var ptSel = document.getElementById("ProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && ptSel != null && lenSel != null)
		{
			GetDropDownData(lenSel,"Select a length","Length","ro=Length&cni=" + catSel.value + "&pni=" + ptSel.value + "&spni=" + spni);
		}
	}
}

function SetHiddenValue(productTypeNumId,postfixId)
{
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	var lenHid = document.getElementById("LengthHid");
	var ptHid = document.getElementById("ProductTypeHid" + postfixId);
	if(catSel != null)
	{
		//For Index Page
		if(ptSel != null && sptSel != null && ptHid != null)
		{
			if(catSel.value != 1)
			{
				ptHid.value = sptSel.value == 0 ? ptSel.value : sptSel.value;
			}
			if(ptSel.selectedIndex <= 0)
			{
				ptHid.value = 0;
			}
		}
	}

	if(lenSel != null && lenHid != null)
	{
		lenHid.value = lenSel.selectedIndex > 0 ? lenSel.options[lenSel.selectedIndex].text : "";
	}
}

function InitalDropDown(postfixId)
{
	postfixId = postfixId == null ? "" : postfixId;

	var bdSel = document.getElementById("BrandSel" + postfixId);
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	ClearDropDown(bdSel,"Select a brand");
	SetDisabled(bdSel,true);
	ClearDropDown(srSel,"Select a series");
	SetDisabled(srSel,true);
	ClearDropDown(mdSel,"Select a model");
	SetDisabled(mdSel,true);
	ClearDropDown(ptSel,"Select a product type");
	SetDisabled(ptSel,true);
	ClearDropDown(sptSel,"Select a sub product type");
	SetDisabled(sptSel,true);
	ClearDropDown(lenSel,"Select a length");
	SetDisabled(lenSel,true);
}

function ClearHiddenValue(postfixId)
{
	postfixId = postfixId == null ? "" : postfixId;

	var ptHid = document.getElementById("ProductTypeHid" + postfixId);
	var lenHid = document.getElementById("LengthHid");
	if(ptHid != null)
	{
		ptHid.value = "";
	}
	if(lenHid != null)
	{
		lenHid.value = "";
	}
}

function ClearDropDown(sel,text)
{
	if(sel != null)
	{
		sel.options.length = 0;
		sel.options.add(new Option(text,"0"));
	}
}

function SetDisabledByLength(sel)
{
	if(sel != null)
	{
		if(sel.length > 1)
		{
			sel.disabled = false;
		}
		else
		{
			sel.disabled = true;
		}
	}
}

function SetDisabled(sel,status)
{
	if(sel != null)
	{
		sel.disabled = status;
	}
}

function SetDefaultValue(sel,val)
{
	if(sel != null)
	{
		sel.value = val;
		if(sel.selectedIndex < 0)
		{
			sel.selectedIndex = 0;
		}
	}
}

function getElementsByNameFixed(tag,name)
{
	var elem = document.getElementsByTagName(tag);
	var count = 0;
	var elements = [];
	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].getAttribute("name") == name)
		{
			elements[count] = elem[i];
			count++;
		}
	}
	return elements;
}
/*Drop Down Search End*/
